package cn.credit.loan.service.user;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.credit.loan.dao.user.UserMapper;
import cn.credit.loan.entity.User;

@Service
@Transactional
public class UserServiceImpl implements UserService{
	
	@Autowired
	private UserMapper userMapper;
	
	/**
	 * 用户登录
	 */
	@Override
	public User userlogin(String userphone) throws Exception {
		if(userphone.trim() != null ){
			User user=userMapper.userlogin(userphone);
			if(user!=null){
				return user;
			}
		}
		return null;
	}
	/**
	 * 用户注册
	 */
	@Override
	public Boolean addUser(User user) throws Exception {
		if(user!=null){
			int faly=userMapper.UserRegistra(user);
			//int faly=userMapper.insert(user);  //调用通用Mapper类里的添加 insert()方法
			if(faly>0){
				return true;
			}
		}
		return false;
	}
	/**
	 * 修改用户登录信息
	 */
	@Override
	public Boolean updateUserBypwd(User user) throws Exception  {
		if(user!=null){
			int num=userMapper.updateByKey(user);
			if(num>0){
				return true;
			}
		}
		return false;
	}
	
	
	
	/**
	 * 用户删除
	 */
	@Override
	public boolean deleteUser(int userId) throws Exception {
		
		return userMapper.deleteUser(userId);
	}
	
	
}
